package com.huatai.exchange.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.dao.ExcFileLoadInfoDAO;
import com.huatai.exchange.dal.model.ExcFileLoadInfo;
import com.huatai.exchange.facade.Contents;
import com.huatai.exchange.service.ExcFileLoadInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcFileLoadInfoServiceImpl implements ExcFileLoadInfoService {

    @Autowired
    private ExcFileLoadInfoDAO excFileLoadInfoDAO ;

    @Override
    public void addExcFileLoadInfo(ExcFileLoadInfo excFileLoadInfo) throws BusinessException {
        try {
            excFileLoadInfoDAO.insert(excFileLoadInfo);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public ExcFileLoadInfo queryExcFileLoadInfo(String id) throws BusinessException {
        ExcFileLoadInfo info = null;
        try {
            info = excFileLoadInfoDAO.queryById(id);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return info;
    }

    @Override
    public List<ExcFileLoadInfo> queryExcFileLoadInfoList(ExcFileLoadInfo excFileLoadInfo) throws BusinessException {
        List<ExcFileLoadInfo> infos = null;
        try {
            infos = excFileLoadInfoDAO.queryByModel(excFileLoadInfo) ;
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return infos;
    }

    @Override
    public void modifyExcFileLoadInfo(ExcFileLoadInfo excFileLoadInfo) throws BusinessException {
        try {
            Long num = excFileLoadInfoDAO.updateById(excFileLoadInfo) ;
            if(num == 0 ){
                throw new BusinessException("更新记录为0，失败") ;
            }
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public List<ExcFileLoadInfo> queryExcFileNeedLoadInfoList() throws BusinessException {
        ExcFileLoadInfo excFileLoadInfo = new ExcFileLoadInfo();
        excFileLoadInfo.setStatus(Contents.boolean_true);
        return queryExcFileLoadInfoList(excFileLoadInfo);
    }
}
